package uni.j2ee.forum.helper;

import com.sun.faces.util.MessageFactory;
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

public class CommonHelper {

	public static void putSessionMap(final String key, final Object value) {
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key, value);
	}
	
	public static Map<String, Object> getRequestMap() {
		ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
		return externalContext.getRequestMap();
	}

	public static void putApplicationMap(final String key, final Object value) {
		FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().put(key, value);
	}
	
	public static void addMessage(final String key, final boolean errorMessage) {
		final FacesMessage facesMessage = MessageFactory.getMessage(key);
		facesMessage.setSeverity(errorMessage?FacesMessage.SEVERITY_ERROR:FacesMessage.SEVERITY_INFO);
		
		FacesContext.getCurrentInstance().addMessage(null, facesMessage);
	}

}
